home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2005 June (DVD) / DPPRO0605DVD.iso / Install / program files / Borland / BDS / 3.0 / Demos / Delphi.Net / CLR / IsDelphiAssembly / IsDelphiNet.dpr < prev   
Encoding:
Text File  |  2004-10-22  |  1.9 KB  |  83 lines

  1. program IsDelphiNet;
  2.  
  3. {$APPTYPE CONSOLE}
  4.  
  5. uses
  6.   System.IO, System.Reflection;
  7.  
  8. type
  9.   TAssemblyKind = (akNotFound, akLoadError, akNotClr, akNonDelphi, akDelphi);
  10.  
  11. function DetectDelphiAssembly(const FileName: string): TAssemblyKind;
  12. var
  13.   A: Assembly;
  14.  
  15.   function DelphiAssemblyDetected: Boolean;
  16.   var
  17.     I: Integer;
  18.     T: array of System.Type;
  19.     R: array of AssemblyName;
  20.   begin
  21.     Result := False;
  22.     T := A.GetTypes;
  23.     for I := Low(T) to High(T) do
  24.       if T[I].Namespace.StartsWith('Borland.Delphi.System') then
  25.       begin
  26.         Result := True;
  27.         Break;
  28.       end;
  29.     if not Result then
  30.     begin
  31.       R := A.GetReferencedAssemblies;
  32.       for I := Low(R) to High(R) do
  33.         if R[I].Name.StartsWith('Borland.Delphi') then
  34.         begin
  35.           Result := True;
  36.           Break;
  37.         end;
  38.     end;
  39.   end;
  40.  
  41. begin
  42.   try
  43.     A := Assembly.LoadFrom(FileName);
  44.     if DelphiAssemblyDetected then
  45.       Result := akDelphi
  46.     else
  47.       Result := akNonDelphi;
  48.   except
  49.     on E: BadImageFormatException do
  50.       Result := akNotClr;
  51.     on E: IOException do
  52.       Result := akNotFound;
  53.     on E: ReflectionTypeLoadException do
  54.       Result := akLoadError;
  55.   end;
  56. end;
  57.  
  58. procedure Run;
  59. var
  60.   FileName: string;
  61. begin
  62.   FileName := ParamStr(1);
  63.   if FileName = '' then
  64.     WriteLn('Usage: isdelphinet <assembly file name>')
  65.   else
  66.     case DetectDelphiAssembly(FileName) of
  67.       akNotFound:
  68.         WriteLn('Assembly not found');
  69.       akLoadError:
  70.         Writeln('Can not load assembly, some referenced assemblies are probably missing');
  71.       akNotClr:
  72.         WriteLn('Specified file is not CLR');
  73.       akNonDelphi:
  74.         WriteLn('Assembly does not seem to be created by Delphi for .NET');
  75.       akDelphi:
  76.         WriteLn('Assembly is written in Delphi for .NET');
  77.     end;
  78. end;
  79.  
  80. begin
  81.   Run;
  82. end.
  83.